﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using WebUI.Helper;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace WebUI.Con.Admin
{
    public class AdminLoginController : Controller
    {
        /// <summary>
        /// 管理员登录密码
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        [Common.Attributes.Skip]
        public ActionResult Login()
        {
            //班次选择绑定的ridioButton数据
            ViewData["Shift"] = OperateContext.Current.BLLSession.IShiftBLL.GetListBy(s => s.ShiftID > 0).Select(s => new Model.ViewModel.Shift { ShfitID = s.ShiftID, ShfitName = s.ShiftName }).ToList(); 
            return View();
        }
        /// <summary>
        /// 管理员登录密码
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Common.Attributes.Skip]
        public ActionResult Login(Model.ViewModel.LoginUser LoginUser)
        {
            
          
            //1.1获取数据
            int id = Convert.ToInt32(LoginUser.shiftID);
            string UserName = LoginUser.LoginName;
            string PassWord = LoginUser.Pwd;
            //string UserName = Request["form-username"].ToString();
            //string PassWord = Request["form-password"].ToString();
            //1.2验证（自己做）
            if (!ModelState.IsValid)
            {
                return OperateContext.Current.RedirectAjax("ERROR", "没有权限", null, "");
            }
            //1.3通过操作上下文获取 用户业务接口对象，调用里面的登陆方法！

            if (OperateContext.Current.LoginAdmin(LoginUser))
            {
               
                return OperateContext.Current.RedirectAjax("OK", "登录成功", OperateContext.Current.Usr, "Index");
            }
            else
            {
                return OperateContext.Current.RedirectAjax("ERROR", "登录失败", null, "");
            }
           

        }
        [Common.Attributes.Skip]
        public ActionResult Index()
        {
            ViewBag.User = OperateContext.Current.Usr;
            
            return View();
        }
    }
}
